home *** CD-ROM | disk | FTP | other *** search
- unit UObj; {Turbo Pascal Version} {90/01/08}
- {
- This unit contains the TObj class and was written to:
-
- 1) provide a "better" base object for Turbo Pascal programmers
- 2) enhance portability between Object Pascal and Turbo Pascal (MS/DOS)
- 3) provide the standard base object to Quick Pascal programmers
-
- Author: Mike Babulic Compuserve: 72307,314
- 3827 Charleswood Dr. N.W.
- Calgary, Alberta
- Canada
- T2L 2C7
- }
- interface
-
- uses Objects;
-
- type
- pTObj = ^TObj;
- TObj = object(Base)
- constructor Bind;
- {"Default" constructor;
- simply performs run-time binding.
- "New(v,Bind)" in Turbo
- is equivalent to:
- "New(v)" in Object Pascal (& Quick Pascal)}
- function Clone: Pointer; virtual;
- {Copies SELF and returns a pointer to the copy
- Can override to copy objects referred to by
- fields of SELF}
- procedure Free; virtual;
- {Frees SELF from the heap.
- Can override to free objects referred to by
- fields of SELF}
- function ShallowClone: Pointer; virtual;
- {Low-level copy; should not be overridden
- except in very unusual cases}
- procedure ShallowFree; virtual;
- {Low-level method for freeing an object.
- Should not be overridden
- except in very unusual cases}
- function Bytes:Longint; virtual;
- {Returns the number of bytes in SELF}
- function TypeOf:Pointer; virtual;
- {Returns TypeOf(SELF)}
- end;
-
- pTObject = ^TObj; {For compatability with Object Pascal programs}
- TObject = TObj;
-
- implementation
-
- constructor TObj.Bind;
- begin
- end;
-
- function TObj.ShallowClone: Pointer;
- var t:pTObj;
- begin
- GetMem(t,SELF.Bytes);
- Move(self,t^,SELF.Bytes);
- ShallowClone := t;
- end;
-
- procedure TObj.ShallowFree;
- var t:pTObj;
- begin
- t := @self;
- FreeMem(t,SELF.Bytes);
- end;
-
- function TObj.Clone: Pointer;
- begin
- Clone := SELF.ShallowClone;
- end;
-
- procedure TObj.Free;
- begin
- SELF.Done;
- SELF.ShallowFree;
- end;
-
- function TObj.Bytes:Longint;
- begin
- Bytes := SizeOf(SELF);
- end;
-
- function TObj.TypeOf:Pointer;
- begin
- TypeOf := System.TypeOf(SELF);
- end;
-
- end.